/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package gestureObservers;

import gesturetracking.ButtonPanel;
import java.awt.Graphics;
import java.awt.Rectangle;
import javax.swing.JFrame;
import org.OpenNI.GestureRecognizedEventArgs;
import org.OpenNI.IObservable;
import org.OpenNI.IObserver;

/**
 *
 * @author xvanek9
 */
public class GestureRecognizedObserver implements IObserver<GestureRecognizedEventArgs>{

    private ButtonPanel panel;
    private JFrame frame;

    public void setFrame(JFrame frame) {
        this.frame = frame;
    }
    
    @Override
    public void update(IObservable<GestureRecognizedEventArgs> io, GestureRecognizedEventArgs args) {
        StringBuilder sb = new StringBuilder();
        if (args.getIdPosition().getX() <=0){
            sb.append("Lefthand ");
        }else{
            sb.append("Righthand ");
        }
        sb.append("gesture ");
        sb.append(args.getGesture());
        sb.append(" recognized at position ");
        sb.append(args.getIdPosition().getX()).append(", ");
        sb.append(args.getIdPosition().getY()).append(", ");
        sb.append(args.getIdPosition().getZ()).append(".");
        System.out.println(sb.toString());
        if (frame != null){
            frame.setTitle(sb.toString());
        }
        if (panel != null){
            panel.pushButton(args.getEndPosition());
        }
    }
    
    public void paintGesture(Graphics g, float x, float y, float z){
        //g.fillOval((int)x, (int)y, 15, 15);
        panel.paintImmediately(new Rectangle(10,10,10,10));
    }
    
    public void paintGesture(){
        panel.paintImmediately(new Rectangle(10,10,10,10));
    }

    public void setPanel(ButtonPanel panel) {
        this.panel = panel;
    }
    
}
